package DataMock;

import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
import java.util.ArrayList;
import java.util.Iterator;

import po.PlanPO;
import appendix.ResultMessage;

import dataservice.PlanDataService;

public class PlanDataMock extends UnicastRemoteObject implements PlanDataService{
	private static final long serialVersionUID = 1L;
	private ArrayList<PlanPO> arr;
	
	public PlanDataMock(ArrayList<PlanPO> arr) throws RemoteException {
		this.arr=arr;
	}

	@Override
	public ResultMessage<?> find(String name) throws RemoteException {
		ResultMessage<PlanPO> rm=null;
		Iterator it=arr.iterator();
		PlanPO plan=null;
		while(it.hasNext()){
			plan=(PlanPO)it.next();
			if((plan.getFlag()).equals(name)){
				rm=new ResultMessage<PlanPO>(plan);
			}
		}
		return rm;
	}

	@Override
	public ResultMessage<?> update(PlanPO po) throws RemoteException {
		if(arr.contains(po)){
			arr.remove(po);
			arr.add(po);
		}else{
			arr.add(po);
		}
		return new ResultMessage<Boolean>(null);
	}

	@Override
	public void init() throws RemoteException {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void finish() throws RemoteException {
		// TODO Auto-generated method stub
		
	}

}
